//
//  GetMusicTool.m
//  MyMusic
//
//  Created by ioser on 17/5/3.
//  Copyright © 2017年 ioser. All rights reserved.
//

#import "GetMusicTool.h"
#import "MJExtension.h"
#import "MusicInfoModel.h"

@implementation GetMusicTool

static NSArray *_allMusicArray;
static MusicInfoModel *_playingMusic;

+ (void)initialize
{
    _allMusicArray = [MusicInfoModel mj_objectArrayWithFilename:@"Musics.plist"];
    _playingMusic = _allMusicArray[2];
}


+ (NSArray *)returnAllMusic
{
    return _allMusicArray;
}

+ (MusicInfoModel *)returnPlayingMusic
{
    return _playingMusic;
}

+ (MusicInfoModel *)nextMusic
{
    // 取出当前播放音乐的 下标
    NSInteger num = [_allMusicArray indexOfObject:_playingMusic];
    
    NSInteger nextNum = ++num;
    if (nextNum >= _allMusicArray.count) {
        nextNum = 0;
    }
    
    MusicInfoModel *model = _allMusicArray[nextNum];
    _playingMusic = model;
    
    return model;
}

+ (MusicInfoModel *)previousMusic
{
   // 取出当前音乐的下标
    NSInteger num = [_allMusicArray indexOfObject:_playingMusic];
    
    NSInteger previous = --num;
    
    if (previous < 0) {
        previous = _allMusicArray.count - 1;
    }
    
    MusicInfoModel *model = _allMusicArray[previous];
    _playingMusic = model;
    return model;
}

@end
